Hi,
how can I get a new Worksheet in a Excel Instance triggered from a DXL script? I have read, that "oleMethod" can do this, but I don't understand the functionality. Can anyone help me?
I have already opened a Excel instance and I have tried to create a new Worksheet with:
oleMethod(objExcel, "Sheets", args, objSheet)
oleMethod(objSheet, "Activate")
The variable "args" is from type OleAutoArgs. args is assigned to: args = null
edit: I use office excel 2010.
tobi_mehrl - Mon Jun 15 04:00:48 EDT 2015 |
Re: New Worksheet in Excel with oleMethod? Wolfgang Uhr - Mon Jun 15 06:22:33 EDT 2015
Hi Tobi
The variable "args" is from type OleAutoArgs. args is assigned to: args = null
That is wrong. If you do not have any parameter, you can odmit it ->
oleMethod(objExcel, "Sheets", objSheet)
Otherwise you have to insert an empty args-object.
To add a new sheet you have to to the same as in VBA. You have to get access to the objExel.Documents-Object and then you have to add a sheet using the vba-command "new".
Best regards
Wolfgang
|
Re: New Worksheet in Excel with oleMethod? tobi_mehrl - Wed Jun 17 04:55:35 EDT 2015
Hi,
my code no follows that:
objExcel = connectToApp(cObjExcelApplication, (NLS_("Excel")))
if (null objExcel)
{
return false
}
makeVisible objExcel
/*// Add a blank new worksheet to Excel.
//olePut(objExcel, "Visible", true)
oleGet(objExcel, "Workbooks", objWorkbooks)
//oleMethod(objWorkbooks, "Add")
oleGet(objExcel, "ActiveWorkbook", objWorkbook)
//clear args
//put(args, 1)
oleGet(objWorkbook, "Sheets", args, objWorksheet)
oleMethod(objWorksheet, "Add")
//Debug
print "Name from opened, current Module: " nameFromCurrentModule "\n"
//Rename activated, current Worksheet
//olePut(objWorksheet, cExcelPropertyName, nameFromCurrentModule)
//clear args*/
// get workbooks collection
checkRes(oleGet(objExcel, cPropertyWorkbooks, objWorkbooks))
if (null objWorkbooks)
{
ack getExtMsg("String_Unable_to_get_workbooks_collection",NLSTEMP_("The export failed because the workbooks collection was not retrieved."))
return false
}
// add one Workbook
checkRes(oleMethod(objWorkbooks, cMethodAdd))
// get active workbook
checkRes(oleGet(objExcel, cPropertyActiveWorkbook, objWorkbook))
if (null objWorkbook)
{
ack getExtMsg("String_Unable_to_get_active_workbook",NLSTEMP_("The export failed because the active workbook cannot be retrieved."))
return false
}
// Add a blank new worksheet to Excel.
checkRes(oleGet(objWorkbook, "Sheets", objSheet))
oleMethod(objSheet, "Add")
// get active sheet
checkRes(oleGet(objWorkbook, cPropertyActiveSheet, objSheet))
if (null objSheet)
{
ack getExtMsg("String_Unable_to_get_active_sheet",NLSTEMP_("The export failed because the client cannot retrieve the active sheet."))
return false
}
//Debug
print "Name from opened, current Module: " nameFromCurrentModule "\n"
//Rename activated, current Worksheet
olePut(objSheet, "Sheetname", nameFromCurrentModule)
return true
I create a new sheet in my Excel-Workbook. With the last olePut(...)-Function, I will change the name of the Worksheet depending on the string variable "nameFromCurrentModule". The problem is, that the code this action don't do. Where is the problem? Can you explain it to me? Better: can you explain me the "OLE-construct"?
|
Re: New Worksheet in Excel with oleMethod? Wolfgang Uhr - Wed Jun 17 09:02:32 EDT 2015 tobi_mehrl - Wed Jun 17 04:55:35 EDT 2015
Hi,
my code no follows that:
objExcel = connectToApp(cObjExcelApplication, (NLS_("Excel")))
if (null objExcel)
{
return false
}
makeVisible objExcel
/*// Add a blank new worksheet to Excel.
//olePut(objExcel, "Visible", true)
oleGet(objExcel, "Workbooks", objWorkbooks)
//oleMethod(objWorkbooks, "Add")
oleGet(objExcel, "ActiveWorkbook", objWorkbook)
//clear args
//put(args, 1)
oleGet(objWorkbook, "Sheets", args, objWorksheet)
oleMethod(objWorksheet, "Add")
//Debug
print "Name from opened, current Module: " nameFromCurrentModule "\n"
//Rename activated, current Worksheet
//olePut(objWorksheet, cExcelPropertyName, nameFromCurrentModule)
//clear args*/
// get workbooks collection
checkRes(oleGet(objExcel, cPropertyWorkbooks, objWorkbooks))
if (null objWorkbooks)
{
ack getExtMsg("String_Unable_to_get_workbooks_collection",NLSTEMP_("The export failed because the workbooks collection was not retrieved."))
return false
}
// add one Workbook
checkRes(oleMethod(objWorkbooks, cMethodAdd))
// get active workbook
checkRes(oleGet(objExcel, cPropertyActiveWorkbook, objWorkbook))
if (null objWorkbook)
{
ack getExtMsg("String_Unable_to_get_active_workbook",NLSTEMP_("The export failed because the active workbook cannot be retrieved."))
return false
}
// Add a blank new worksheet to Excel.
checkRes(oleGet(objWorkbook, "Sheets", objSheet))
oleMethod(objSheet, "Add")
// get active sheet
checkRes(oleGet(objWorkbook, cPropertyActiveSheet, objSheet))
if (null objSheet)
{
ack getExtMsg("String_Unable_to_get_active_sheet",NLSTEMP_("The export failed because the client cannot retrieve the active sheet."))
return false
}
//Debug
print "Name from opened, current Module: " nameFromCurrentModule "\n"
//Rename activated, current Worksheet
olePut(objSheet, "Sheetname", nameFromCurrentModule)
return true
I create a new sheet in my Excel-Workbook. With the last olePut(...)-Function, I will change the name of the Worksheet depending on the string variable "nameFromCurrentModule". The problem is, that the code this action don't do. Where is the problem? Can you explain it to me? Better: can you explain me the "OLE-construct"?
Hi Tobi
You must not use ActiveWorkbook.
ActiveWorkbook ist a VBA internal property which gets an access to the actual document which is real active on the destop. A simple mouse click or something else can change this.
You have to use the Application.Workbooks-Object
If you use the add-method of the worksheets-object you have to define a minimal set of arguments, isn't it?
Write a small vba-code snippet to learn the set of parameters you have to define and define them in args.
Best regards
Wolfgang
|